from bs4 import BeautifulSoup
from selenium import webdriver
from browsermobproxy import Server
import json
import time



header={
'tcyVersion': '5.5.0',
'tcyPackage': 'com.uc108.mobile.gamecenter', 
'nickName': '%E9%92%AE%E9%9A%86%E4%BD%B3%E5%AE%81',
'soVersion': '1.4.20180402', 'City': '%E6%9D%AD%E5%B7%9E%E5%B8%82',
'AccessToken': '3SI-2EkO2dx8XAqJLp7Xffkzr7gnfwuhHMTjcBm3RMKGSUQ9xXsCyG-fZsAf-yg1w8X1Y1tmg0YJpc5X5riMAyN1PagSuaJj0y5Q4IgabigQ7SNNrYbFqcWpuYF1jsFHthokiZ6cAjhpIT6Osf3iGw',
'timestamp': '1527211696406',
'tcyCode': '77',
'tcyPromoter': '310200',
'userName': 'bcndjdjdhf', 
#'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; vivo X6Plus D Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043632 Safari/537.36', 
'network': '3',
'checkcode': '1cc9eae3158649dc10a5376de4e24d6e',
'Province': '%E6%B5%99%E6%B1%9F%E7%9C%81',
'system': '1',
'IMEI': '868964029385133',
'userid': '678086',
'Cookie': 'Hm_lvt_cd942ae8726c37cd4d5e7e75c5ba0df8=1527412852; Hm_lpvt_cd942ae8726c37cd4d5e7e75c5ba0df8=1527146074; Hm_lvt_cdcf9362b8b5cece63d03595c79a941c=1527407548; Hm_lpvt_cdcf9362b8b5cece63d03595c79a941c=1527211696',
'District': '%E6%BB%A8%E6%B1%9F%E5%8C%BA'}

#result = get('http://exchangemall.tcysys.tcy365.org:1507/Static/index.html',headers=header,stream=True)

server = Server("D://proxy/bin/browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()

#http://exchangemall.tcysys.tcy365.org:1507/api/UserTicket

profile  = webdriver.FirefoxProfile()
'''p=webdriver.Proxy({
            "httpProxy": 'localhost:8112',
            "sslProxy": 'localhost:8112',
        })'''
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)


proxy.new_har("test",options={'captureHeaders':True,'captureContent':True})
proxy.headers(header)
driver.get('http://exchangemall.tcysys.tcy365.org:1507/Static/index.html')



time.sleep(5)
soup = BeautifulSoup(str(driver.page_source.encode('utf8')), "lxml")
print(soup.find(id="jq_ticketNum"))
with open('index.txt','w') as wf:
	wf.write(json.dumps(proxy.har,indent=4))

server.stop()

driver.quit()


